{#
Renders an author info snippet.
If there's no data for the author, just renders their ID. This isn't ideal but is better than
crashing.
If there are more than 3 authors, it will render a condensed view
#}
{% macro postAuthor(authors, locale) %}

  {#
  Renders the default author view if there are less than three authors
  #}
  {% if authors.length < 3 %}
<div class="post-authors">
  {% for authorId in authors %}
    {% set author = authorsData[authorId] %}
    {% set authorTitle = 'i18n.authors.' + authorId + '.title' %}
    {% set authorDescription = 'i18n.authors.' + authorId + '.description' %}
    {% set authorImage = author.image or site.defaultAvatarImg %}
    <div class="display-flex align-start">
      {# Display author image if available #}
      {% if authorImage %}
        <a href="/authors/{{authorId}}/" translate="no" class="card-authors__image">
          {% Img
            class="flex-shrink-none width-600 height-600",
            src=authorImage,
            alt=authorTitle | i18n(locale),
            width="40",
            height="40",
            options={minWidth: 40, maxWidth: 120}
          %}
        </a>
      {% endif %}
      <div class="display-flex direction-column align-start gap-left-300 type--small">
        {# Display author name and description if available, otherwise just the author ID #}
        {% if author %}
          <a href="/authors/{{authorId}}/" translate="no" class="surface display-inline-flex color-text">{{ authorTitle | i18n(locale) }}</a>
          <p class="color-secondary-text">{{ authorDescription | i18n(locale) }}</p>

          {# Start author social links #}
          <div class="post-authors-social">
            {% if author.homepage %}
              <a rel="me" href="{{ author.homepage }}" class="link">{{ 'i18n.common.website' | i18n(locale) }}</a>
            {% endif %}
            {% if author.twitter %}
              <a rel="me" href="https://twitter.com/{{ author.twitter }}" class="link">Twitter</a>
            {% endif %}
            {% if author.github %}
              <a rel="me" href="https://github.com/{{ author.github }}" class="link">GitHub</a>
            {% endif %}
            {% if author.glitch %}
              <a rel="me" href="https://glitch.com/@{{ author.glitch }}" class="link">Glitch</a>
            {% endif %}
            {% if author.mastodon %}
              <a rel="me" href="{{ author.mastodon }}" class="link">Mastodon</a>
            {% endif %}
            {% if author.linkedin %}
              <a rel="me" href="https://www.linkedin.com/in/{{ author.linkedin }}" class="link">LinkedIn</a>
            {% endif %}
          </div>
          {# End author social links #}
        {% else %}
          <p>{{ authorId }}</p>
        {% endif %}
      </div>
    </div>
  {% endfor %}
</div>

{#
Renders a condensed view if there are 3 or more authors
#}

  {% else %}
    {# Display author images in a row for condensed view #}
    <div class="display-flex align-start">
    {% for authorId in authors %}
      {% set author = authorsData[authorId] %}
      {% set authorTitle = 'i18n.authors.' + authorId + '.title' %}
      {% set authorDescription = 'i18n.authors.' + authorId + '.description' %}
      {% set authorImage = author.image or site.defaultAvatarImg %}
      {# Display author image if available #}
      {% if authorImage %}
        <a href="/authors/{{authorId}}/" translate="no" class="post-authors__image">
          {% Img
            class="flex-shrink-none width-750 height-750",
            src=authorImage,
            alt=authorTitle | i18n(locale),
            width="50",
            height="50",
            options={minWidth: 50, maxWidth: 120}
          %}
        </a>
      {% endif %}
    {% endfor %}
    </div>

    {# Display author names in a condensed format #}
    <div class="gap-top-200">
      <p class="type--small">
        By
        {% set sep = joiner(', ') %}
        {%- for authorId in authors -%}
          {%- if loop.last -%}
            {{- ' and ' -}}
          {%- else -%}
            {{- sep() -}}
          {%- endif -%}
          {%- if authorsData[authorId] -%}
            {% set authorTitle = 'i18n.authors.' + authorId + '.title' %}
            {% set authorImage = authorsData[authorId].image or site.avatarPlaceholderImg %}
            <a href="/authors/{{authorId}}/" translate="no" class="display-inline-flex color-text decoration-underline">{{ authorTitle | i18n(locale) }}</a>
          {%- else -%}
            {{ authorId }}
          {%- endif -%}
        {%- endfor -%}
      </p>
    </div>
  {% endif %}
{% endmacro %}
